<?php
namespace App\Http\Controllers\Admin;

use App\Service\Admin\UtagService;
use Illuminate\Http\Request;

class UtagController extends BaseController
{
    //用户标签

    public function __construct(UtagService $service)
    {
        $this->db = $service;
    }

    //列表
    public function getList(Request $request)
    {
        $uid = $request->post('uid', 0);
        $res = $this->db->getList($uid);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data'], $res['total']);
    }

    //删除
    public function add(Request $request)
    {
        $uid = $request->post('uid', 0);
        $title = $request->post('title', '');
        if (!$uid) {
            return $this->toJson(-2, '用户ID必须的');
        }
        $res = $this->db->add($uid, $title);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson();
    }

    //删除
    public function del(Request $request)
    {
        $id = $request->post('id', 0);
        if (!$id) {
            return $this->toJson(-2, '门店ID必须的');
        }
        $res = $this->db->del($id);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson();
    }
}